package com.wanaofu.dao;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public abstract class AbstractBaseDAO {
	@Resource
    protected SessionFactory sessionFactory;   
	
//	@Resource
//	protected Validator validator;
//    protected Class<?> entityClass;   
    /**  
     * 获取在该对象之上的Criteria实例对象      
     * @return Criteria实例对象  
     */   
    protected Criteria getBaseCriteria(Class<?> entityClass) {   
        return getSession().createCriteria(entityClass);   
    }   
  
    protected final Session getSession() {  
    	return this.sessionFactory.getCurrentSession(); 
    }   
    protected Object get(Class<?> clazz, Serializable id) {        
        return this.getSession().get(clazz,id);  
    }  
    protected Object load(Class<?> clazz, Serializable id) {          
        return this.getSession().load(clazz,id);  
    }  
  
    /** 
     * 返回所以对象实例 
     *  
     * @param clazz 
     * @return 
     */  
    public List<?> getAll(Class<?> clazz) {         
        return (List<?>)this.getBaseCriteria(clazz).list();  
    }      
 
}
